﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Entity;
using DAL;

namespace CafeTek
{
    public partial class frmLogin : Form
    {
        public static Employee _emp;
        EmployeeDB _empDB;
        
        public frmLogin()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            _empDB = new EmployeeDB();
            int id;
            if (txtId.Text.Equals("") && txtpass.Text.Equals(""))
            {
                MessageBox.Show("Username or Password is clear", "Information!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                //check Id have is number ?
                if (!int.TryParse(txtId.Text.Trim(), out id))
                {
                    MessageBox.Show("Id only number");
                    return;
                }
                _emp = _empDB.returnEmployee(id, txtpass.Text.Trim());

                if (_emp != null)
                {
                    this.Hide();
                    FrmMain f = new FrmMain();
                    f.Show();
                }
                else
                    MessageBox.Show("Username or Password is wrong", "Information !!!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
